package org.datedemo;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;

public class BetweenDemo {
    public static void main(String[] args) {
        //LocalDate 差值
        LocalDate d1 = LocalDate.of(1988,6,1);
        LocalDate d2 = LocalDate.of(2020,6,8);
        long nn = ChronoUnit.DAYS.between(d1, d2);
        System.out.println(nn);
        long yy = ChronoUnit.YEARS.between(d1, d2);
        System.out.println(yy);

        //LocalTime 差值
        LocalTime t1 = LocalTime.of(5,0,10);
        LocalTime t2 = LocalTime.now();
        long mm = ChronoUnit.MINUTES.between(t1, t2);
        System.out.println(mm);

        //LocalDateTime
        LocalDateTime dt1 = LocalDateTime.of(d1,t1);
        LocalDateTime dt2 = LocalDateTime.of(d2,t2);
        long wk = ChronoUnit.WEEKS.between(dt1, dt2);
        System.out.println(wk);

        //计算生活了多少秒
        var d3 =  LocalDateTime.of(2000,1,1,0,0,0);
        var d4 =  LocalDateTime.now();
        System.out.printf("%tF %<tT 到 %2$tF %<tT 共有 %3$,d 秒",d3,d4,ChronoUnit.SECONDS.between(d3,d4));


    }
}
